<?php

class Model_jawaban extends CI_Model {
	
	public function jawaban()
	{
		$soal		= $this->get_soal();
		$no = 0;
		foreach($soal as $id_soal){
			$kunci		 = $this->get_kunci($id_soal['id']);
			$jawaban	 = $this->get_jawaban($id_soal['id']);
			foreach($kunci as $id_kunci){
				$data[$no]['kalimat'] = $id_kunci['kunci'];
				$data[$no]['skor']	  = $id_kunci['skor'];
				$no++;
			}
			foreach($jawaban as $id_jawaban){
				$data[$no]['kalimat'] = $id_jawaban['jawaban'];
				$data[$no]['skor']	  = '';
				$no++;
			}
		}
		
		return $data;
	}
	
	public function jawaban_ngram()
	{
		$soal		= $this->get_soal();
		$no = 0;
		foreach($soal as $id_soal){
			$kunci		 = $this->get_kunci($id_soal['id']);
			foreach($kunci as $id_kunci){
				$data[$no]['kalimat'] = $id_kunci['kunci'];
				$data[$no]['skor']	  = $id_kunci['skor'];
				$no++;
			}
		}
		
		return $data;
	}
	
	public function get_soal()
	{
		$this->db->select('*');
		$this->db->from('soal');
		$this->db->order_by('id','Desc');
		$query = $this->db->get();
		return $query->result_array();
	}
	
	public function get_kunci($id_soal)
	{
		$this->db->select('*');
		$this->db->from('kunci');
		$this->db->where('id_soal', $id_soal);
		$this->db->order_by('id_soal','Desc');
		$query = $this->db->get();
		return $query->result_array();
	}
	
	public function get_jawaban($id_soal)
	{
		$this->db->select('*');
		$this->db->from('jawaban_user');
		$this->db->where('id_soal', $id_soal);
		$this->db->order_by('id_soal','Asc');
		$query = $this->db->get();
		return $query->result_array();
	}
	
}